﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.LogicLayer;
namespace Server_NhaSach.BusinessLayer
{
    [Serializable]
    public class HoaDonBanSiBlo
    {
                #region "Khai báo các biến"
        private HoaDonBanSiDAO da;
        private HoaDonBanSiDTO _hDBS;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        public HoaDonBanSiDTO HDBS
        {
            get { return _hDBS; }
            set { _hDBS = value; }
        }
        #endregion
        #region "Khai báo các Method"
        public HoaDonBanSiBlo()
        {
            _hDBS = new HoaDonBanSiDTO();
            da = new HoaDonBanSiDAO();
        }
        public bool InsertHDBS(string maHDBS, string maKho, string maKH, string maNV, string nguoiMua, DateTime ngayBanSi, string chungTuBanSi, string ghiChuBS, string diaChiGiao, float vAT, double tongThanhTien, double soTienDaTra, double soTienConLai, DateTime ngayHenThanhToan)
        {
            HDBS = new HoaDonBanSiDTO(maHDBS, maKho, maKH, maNV, nguoiMua, ngayBanSi, chungTuBanSi, ghiChuBS, diaChiGiao, vAT, tongThanhTien, soTienDaTra, soTienConLai, ngayHenThanhToan);
            if (!da.InsertHDBS(HDBS))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public bool UpdateHDBS(string maHDBS, string maKho, string maKH, string maNV, string nguoiMua, DateTime ngayBanSi, string chungTuBanSi, string ghiChuBS, string diaChiGiao, float vAT, double tongThanhTien, double soTienDaTra, double soTienConLai, DateTime ngayHenThanhToan)
        {
            HDBS = new HoaDonBanSiDTO(maHDBS, maKho, maKH, maNV, nguoiMua, ngayBanSi, chungTuBanSi, ghiChuBS, diaChiGiao, vAT, tongThanhTien, soTienDaTra, soTienConLai, ngayHenThanhToan);
            if (!da.UpdateHDBS(HDBS))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public bool DeleteHDBS(string MaHDBS)
        {
            if (!da.DeleteHDBS(MaHDBS))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public DataSet LayDS_HoaDonBanSi()
        {
            DataSet ds = new DataSet();
            ds = da.LayDS_HoaDonBanSi();
            return ds;
        }
        #endregion
    }
}